package nextoffer.gaotu;

import java.util.Scanner;

public class Second {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
//        while (in.hasNextInt()) { // 注意 while 处理多个 case
            String a = in.next();
            int b = in.nextInt();

        String[] split = a.split(",");
        int[] arr = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            arr[i] = Integer.parseInt(split[i]);
        }
        int l =  0 , r=  arr.length - 1;
        int len = Integer.MAX_VALUE;
        int sum[] = new int[arr.length + 1];
        for (int i = 1; i < arr.length + 1; i++) {
            sum[i] = sum[i - 1] + arr[ i - 1];
        }
        for (int i = 0; i < sum.length; i++) {
            for (int j = i; j < sum.length; j++) {
                if(sum[j] - sum[i] == b){
                    len = Math.min(len, j - i);
                }
            }
        }

        System.out.println(len == Integer.MAX_VALUE ? 0 : len);

    }
}
